<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <span>东软云医院His系统</span>
      </div>
      <el-button type="danger" round @click="logout">退出</el-button>
    </el-header>
    <!-- 主体容器 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!-- 折叠效果 -->
        <div class="toggle-btn" @click="toggleCollapse">
          <i class="el-icon-tickets"></i>
        </div>
        <!-- 侧边栏菜单 -->
        <el-menu
          background-color="#FFFFFF" 
          text-color="#303133"
          active-text-color="#409fff"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition="false"
          router
          :default-active="activePath"
        >
          <!-- 一级菜单 -->
          <el-submenu :index="item.his_Id+''" v-for="item in menuList" :key="item.his_Id">
            <template slot="title">
              <!-- <i :class="icons[item.his_Id]"></i> -->

              <span>
                <i class="el-icon-document"></i>
                {{item.his_Name}}
              </span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              :index="subItem.path"
              v-for="subItem in item.management"
              :key="subItem.m_Id"
              @click="navState(subItem.path)"
            >
              <!-- 二级菜单的模板 -->
              <template slot="title">
                <!-- <i :class="el-icon-menu"></i> -->
                <i class="el-icon-star-off"></i>
                <span>{{subItem.m_Name}}</span>
              </template>
            </el-menu-item>
          </el-submenu>

          <!-- <template slot="title">
            <i class="el-icon-menu"></i>
            <span>{{subItem.authName}}</span>
            </template>
        </el-menu-item>
          </el-submenu>-->
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <!-- 这是一个路由点位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      //左侧菜单的数据
      menuList: [],
      icons: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      //表示不折叠
      isCollapse: false,
      activePath: "",
    };
  },
  created() {
    this.getMenuList();
    //从sessionStorage中获取到activePath并赋值给属性activePath
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  methods: {
    logout() {
      //清除sessionStorage中的数据(token)
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenuList() {
      //需要向后台发送axios请求获取数组
      const { data: res } = await this.$http.get(
        "hissytemcontroller/selectHis"
      );
      // 判断数据是否获取到了
      console.log("--------------------------------");
      console.log(res);
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menuList = res.data;
    },
    toggleCollapse() {
      //处理菜单的折叠效果
      this.isCollapse = !this.isCollapse;
    },
    //链接的激活状态
    navState(path) {
      window.sessionStorage.setItem("activePath", path);
    },
  },
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #409eff;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #ffffff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #ffffff;
  .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: #f5f5f5;
}
.iconfont {
  margin-right: 12px;
}

.toggle-btn {
  background-color: #909399;
  font-size: 10px;
  color: #ffffff;
  letter-spacing: 2px;
  text-align: center;
  line-height: 22px;
  cursor: pointer;
}
</style>

